package io.finer.erp.jeecg.bas.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import io.finer.erp.jeecg.bas.entity.ZrkQzOrder;

/**
 * @Description: 分切/切张单
 * @Author: jeecg-boot
 * @Date:   2020-10-14
 * @Version: V1.0
 */
public interface ZrkQzOrderMapper extends BaseMapper<ZrkQzOrder> {
	
	/**
	 * @Description 用于pda设备查询工序使用 ，为方便前端展示，将物料名称存储在material_id中
	 *              ，将设备名称存储在order_process_id中，将工序名称存储在process_id中
	 * @param orderId
	 * @return
	 * Create at: 2020-10-08 10:07:29
	 * @author: duanyong
	 * Revision:
	 *    2020-10-08 10:07:29 - first revision by duanyong
	 *        
	 */
	@Select("SELECT o.id,m.name as material_id,d.device_name as order_process_id, t.device_tpye_name as process_id FROM zrk_qz_order o LEFT JOIN bas_material m on o.material_id = m.id LEFT JOIN zrk_order_process p ON o.order_process_id = p.id LEFT JOIN zz_device d ON p.device_id=d.id LEFT JOIN zz_device_type t ON o.process_id=t.id WHERE o.order_process_id IN (select id from zrk_order_process p where order_id = #{orderId}) and o.is_finish=1")
	List<ZrkQzOrder> getQzOrderByOrderId(@Param("orderId")String orderId);

	/**
	 * 根据任务单id查询生产单信息
	 * @param id
	 * @return
	 */
	@Select("SELECT *  FROM zrk_qz_order  WHERE order_process_id like concat('%', #{id,jdbcType=VARCHAR}, '%') and del_flag != 1 ")
	List<ZrkQzOrder> getQzOrderByOrderProcessId(@Param("id")String id);

	/**
	 * 查询拆单后的分切生产单信息
	 * @param parentId
	 * @return
	 */
	@Select("SELECT id, mes_Order_Status FROM zrk_qz_order  WHERE parent_Id=#{parentId}")
	List<ZrkQzOrder> getQzOrderByParentId(@Param("parentId")String parentId);
	
	/**
	 * 分页查询复合单信息
	 * @param page
	 * @param operatorUsers
	 * @param isFinish
	 * @param machineId
	 * @author: xu-zs
	 * Revision:
	 *    2021-04-14 11:24:24 - first revision by xu-zs
	 * @return
	 */
	IPage<ZrkQzOrder> getPageList(Page<ZrkQzOrder> page,@Param("z")ZrkQzOrder z);
	
	/**
	 * @Description 分页查询分切单信息
	 * @param page
	 * @param z
	 * @return
	 * Create at: 2021-09-03 10:50:44
	 * @author: xzs
	 * Revision:
	 *    2021-09-03 10:50:44 - first revision by xzs
	 *
	 */
	IPage<ZrkQzOrder> getPageFQList(Page<ZrkQzOrder> page,@Param("z")ZrkQzOrder z);
	
	/**
	 * @Description 分页查询切张单信息
	 * @param page
	 * @param z
	 * @return
	 * Create at: 2021-09-03 10:50:44
	 * @author: xzs
	 * Revision:
	 *    2021-09-03 10:50:44 - first revision by xzs
	 *
	 */
	IPage<ZrkQzOrder> getPageQZList(Page<ZrkQzOrder> page,@Param("z")ZrkQzOrder z);
	
	/**
	 * 排序查询复合单信息
	 * @param page
	 * @param operatorUsers
	 * @param isFinish
	 * @param machineId
	 * @author: xu-zs
	 * Revision:
	 *    2021-04-14 11:24:24 - first revision by xu-zs
	 * @return
	 */
	List<ZrkQzOrder> getList(String operatorUsers,Integer isFinish,String machineId,String glue);

}
